package game.targets;

import game.targets.screen.ScreenHandler;
import game.targets.sound.NullAudio;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.Bullet;
import com.badlogic.gdx.physics.bullet.collision.btCollisionDispatcher;
import com.badlogic.gdx.physics.bullet.collision.btDbvtBroadphase;
import com.badlogic.gdx.physics.bullet.collision.btDefaultCollisionConfiguration;
import com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld;
import com.badlogic.gdx.physics.bullet.dynamics.btSequentialImpulseConstraintSolver;

public class Targets extends Game {
	
	private btDefaultCollisionConfiguration collisionConfiguration;
	private btCollisionDispatcher dispatcher;
	private btDbvtBroadphase broadphase;
	private btSequentialImpulseConstraintSolver solver;
	private btDiscreteDynamicsWorld world;
	private CollisionHandler handler;
	private ScreenHandler screenHandler;
	
	@Override
    public void create() {
//        readSave();
		Locator.init(this, 1);
		Bullet.init();
        initWorld();
        handler=new CollisionHandler();
        handler.enable();
		screenHandler=new ScreenHandler(this);
        Locator.provideAudio(new NullAudio());
        //Locator.provideAudio(new ConsoleAudio());
        Locator.getAudio().pickMusic();
        Locator.provideHandler(screenHandler);
        screenHandler.setStartScreen();
        
        
    }

    private void initWorld() {
    	collisionConfiguration = new btDefaultCollisionConfiguration(); //collision configuration contains default setup for memory, collision setup
    	dispatcher			 = new btCollisionDispatcher(collisionConfiguration); //use the default collision dispatcher 
    	broadphase		  	 = new btDbvtBroadphase();
    	solver			 	 = new btSequentialImpulseConstraintSolver(); //the default constraint solver
    	world=new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
    	world.setGravity(new Vector3(0,-4.9f,0));
		Locator.provideWorld(world);
	}

	public void readSave() {
    	Preferences prefs = Gdx.app.getPreferences("My Preferences");
    //	level = prefs.getInteger("MaxLevel", DEFAULT_LEVEL);
    }

    @Override
    public void render() {
        super.render();
    }

    @Override
    public void dispose() {
        super.dispose();
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);
    }

    @Override
    public void pause() {
        super.pause();
    }

    @Override
    public void resume() {
        super.resume();
    }
}
